package double_pointer;

public class MaxArea {
    //盛水最多的容器
    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int ret = 0;// 记录最大值
        while (left < right) {
            int tmp = Math.min(height[left], height[right]) * (right - left);
            ret = Math.max(ret, tmp);
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return ret;
    }
    // public int maxArea(int[] height) {
    //     int left = 0;
    //     int right = height.length - 1;
    //     int tmp = 0;
    //     int max = 0;//记录最大值
    //     while (left < right) {
    //         if(height[left] < height[right]) {
    //             tmp = height[left] * (right - left);
    //             left++;
    //             if(tmp > max) {
    //                 max = tmp;
    //             }
    //         } else {
    //             tmp = height[right] * (right - left);
    //             right--;
    //             if(tmp > max) {
    //                 max = tmp;
    //             }
    //         }
    //     }
    //     return max;
    // }
}
